# -*- coding: utf-8 -*-

from sqlalchemy import create_engine,Column,Integer,String,ForeignKey,DATE
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

#创建引擎,用于指定操作的数据库
engine = create_engine(
    'mysql+pymysql://root:123456@127.0.0.1/tedu1909?charset=utf8',
    encoding = 'utf8',
    echo = True #在终端上打印debug日志信息
)

#创建会画类,用于链接到数据库,通过会画链接操作数据库
Session = sessionmaker(bind=engine)

#创建实体类(数据库表中对应的类)的基类
Base = declarative_base()

#创建实体类
class Department(Base):
    __tablename__ = 'departments'   #声明该类与哪个表关联
    dep_id = Column(Integer,primary_key=True)
    dep_name = Column(String(20),unique=True)

class Employee(Base):
    __tablename__ = 'employees'
    emp_id = Column(Integer, primary_key=True)
    emp_name = Column(String(20), unique=True)
    email = Column(String(50))
    dep_id = Column(Integer,ForeignKey('departments.dep_id'))

class Salary(Base):
    __tablename__ = 'salary'
    id = Column(Integer,primary_key=True)
    date = Column(DATE)
    basic = Column(Integer)
    awards = Column(Integer)
    emp_id = Column(Integer,ForeignKey('employees.emp_id'))

if __name__ == '__main__':
    Base.metadata.create_all(engine)
